Skip to content

feat: Add inline editing for tables on desktop (V2)#89166

Open
mohammadjafarinejad wants to merge 47 commits into
Expensify:mainfrom
mohammadjafarinejad:fix/82534-v2
Open

feat: Add inline editing for tables on desktop (V2)#89166
mohammadjafarinejad wants to merge 47 commits into
Expensify:mainfrom
mohammadjafarinejad:fix/82534-v2

Conversation

@mohammadjafarinejad
Copy link
Copy Markdown
Contributor

@mohammadjafarinejad mohammadjafarinejad commented Apr 29, 2026

This reverts commit 78be79e.

Explanation of Change

This PR reapplies #83127 (inline editing for tables on desktop), which was reverted in #88751, with the original issues fixed and additional improvements.

Fixed Issues

$ #82534
$ #88711
PROPOSAL: #82534 (comment)

Tests

  1. Open the app and navigate to the Search/Expenses table on desktop (wide layout)
  2. Click a date cell on any transaction row — verify a date picker popover appears anchored to the cell
  3. Select a new date — verify the cell updates and the popover closes
  4. Click a merchant cell — verify it becomes an inline text input with the current value pre-filled
  5. Edit the text and click away (blur) — verify the new value is saved and the cell returns to display mode
  6. Repeat steps 4–5 for description and amount cells
  7. Click a category cell — verify the category picker popover appears
  8. Select a category — verify the cell updates and the popover closes
  9. Click a cell on a row where editing is not permitted (e.g. no policy) — verify no edit mode is triggered
  • Verify that no errors appear in the JS console

Offline tests

  1. Disable network connection
  2. Edit a cell value — verify the optimistic update is reflected immediately in the UI
  3. Re-enable network — verify the value syncs correctly with the backend

QA Steps

Same as tests.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

This reverts commit 78be79e.

Co-authored-by: Copilot <copilot@github.com>
@melvin-bot
Copy link
Copy Markdown

melvin-bot Bot commented Apr 29, 2026

Hey! I see that you made changes to our Form component. Make sure to update the docs in FORMS.md accordingly. Cheers!

mohammadjafarinejad and others added 5 commits April 29, 2026 15:20
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 29, 2026

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/App.tsx 100.00% <ø> (ø)
src/CONST/index.ts 92.30% <ø> (ø)
src/components/CategoryPicker/index.tsx 3.44% <ø> (ø)
src/components/DatePicker/CalendarPicker/index.tsx 96.57% <100.00%> (+0.02%) ⬆️
src/components/Modal/BaseModal.tsx 87.68% <100.00%> (+0.18%) ⬆️
src/components/MoneyRequestAmountInput.tsx 74.07% <100.00%> (+0.48%) ⬆️
src/components/Search/SearchContext.tsx 50.00% <100.00%> (+0.42%) ⬆️
...components/Search/SearchList/ListItem/DateCell.tsx 100.00% <100.00%> (ø)
src/components/Search/SearchTableHeader.tsx 50.57% <ø> (ø)
...omponents/Table/EditableCell/useInlineEditState.ts 100.00% <100.00%> (ø)
... and 31 more
... and 21 files with indirect coverage changes

@trjExpensify
Copy link
Copy Markdown
Contributor

@mohammadjafarinejad when can you have this ready for review?

@dubielzyk-expensify
Copy link
Copy Markdown
Contributor

And let us know when we can adhoc test build 😄

@trjExpensify
Copy link
Copy Markdown
Contributor

Bump @mohammadjafarinejad. Can we get daily updates please to get this back out?

@trjExpensify
Copy link
Copy Markdown
Contributor

Bump again @mohammadjafarinejad. Please provide an update.

@mohammadjafarinejad
Copy link
Copy Markdown
Contributor Author

@trjExpensify I'll have it ready for review by tomorrow, after I test it to make sure all bugs are fixed.

@trjExpensify
Copy link
Copy Markdown
Contributor

Okay, thank you.

@mohammadjafarinejad
Copy link
Copy Markdown
Contributor Author

@ahmedGaber93 Ready for re-review.

@trjExpensify
Copy link
Copy Markdown
Contributor

@ahmedGaber93 for now I think we should allow the Amount column to be editable in-line, but the Total column not editable in-line in all cases.

Make the total editable if there are no foreign expenses since it already has the value of the amount.

I agree this could be a possible alternative, but it's implicit logic that isn't super obvious, so I think let's reserve it for a follow-up if necessary.

Copy link
Copy Markdown
Contributor

@ahmedGaber93 ahmedGaber93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just two comments, then we can move forward

Comment thread src/components/DatePicker/CalendarPicker/YearPickerModal.tsx
Comment thread src/hooks/useTransactionInlineEdit.ts Outdated
hash,
transactionID,
parentReport: parentReport ?? fallbackReport,
transactionThreadReport: transactionThreadReport ?? parentReport ?? fallbackReport,
Copy link
Copy Markdown
Contributor

@ahmedGaber93 ahmedGaber93 May 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mohammadjafarinejad Passing parentReport as a fallback here is causing an issue for me. When editing a cell from Spend > Expenses, a system message is added to both the expense report and the transaction report.

I think we should avoid falling back to parentReport here.

Suggested fix:
const transactionThreadReportFallback: OnyxEntry<Report> = transactionThreadReportID ? ({reportID: transactionThreadReportID} as Report) : undefined;

and pass it into getEditParams and getTransactionEditPermissions

transactionThreadReport: transactionThreadReport ?? transactionThreadReportFallback,
Screen.Recording.2026-05-07.at.1.31.13.AM.mov

Copy link
Copy Markdown
Contributor

@ahmedGaber93 ahmedGaber93 May 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mohammadjafarinejad I removed the suggested fix on the comment above. Although it works since the correct reportID is being passed, the missing attributes on the report could lead to unexpected issues and it feels like a fragile solution.

What cases cause this report to be missing? And what would happen if we don’t provide a fallback at all?

Copy link
Copy Markdown
Contributor Author

@mohammadjafarinejad mohammadjafarinejad May 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahmedGaber93 We need transactionThreadReport to update the report actions, but sometimes, especially for unreported expenses, it's undefined, which I think is related to this bug too:

I was able to solve it using the changes below. We already have similar logic in BulkEdit, where we resolve missing context for unreported expenses and recreate the transaction thread when needed. WDYT about this approach?

Diff Patch
diff --git a/src/components/MoneyRequestReportView/MoneyRequestReportTransactionItem.tsx b/src/components/MoneyRequestReportView/MoneyRequestReportTransactionItem.tsx
index 6ed8a8ce984..8f16707f6c0 100644
--- a/src/components/MoneyRequestReportView/MoneyRequestReportTransactionItem.tsx
+++ b/src/components/MoneyRequestReportView/MoneyRequestReportTransactionItem.tsx
@@ -129,7 +129,7 @@ function MoneyRequestReportTransactionItem({
         onEditAmount,
         onEditTag,
         wasEditingOnMouseDownRef,
-    } = useTransactionInlineEdit({transactionID: transaction.transactionID, reportID: transaction.reportID});
+    } = useTransactionInlineEdit({transactionID: transaction.transactionID});
 
     const viewRef = useRef<View>(null);
 
diff --git a/src/components/Search/SearchList/ListItem/TransactionListItem.tsx b/src/components/Search/SearchList/ListItem/TransactionListItem.tsx
index 3483e2075d7..39cbfca4f22 100644
--- a/src/components/Search/SearchList/ListItem/TransactionListItem.tsx
+++ b/src/components/Search/SearchList/ListItem/TransactionListItem.tsx
@@ -175,8 +175,6 @@ function TransactionListItem<TItem extends ListItem>({
     const {isDelegateAccessRestricted} = useDelegateNoAccessState();
     const {showDelegateNoAccessModal} = useDelegateNoAccessActions();
 
-    const transactionID = transactionItem.transactionID;
-
     const {isEditingCell, wasRecentlyEditingCell} = useEditingCellState();
     const [shouldDisableHoverStyle, setShouldDisableHoverStyle] = useState(false);
 
@@ -205,12 +203,9 @@ function TransactionListItem<TItem extends ListItem>({
         onEditTag,
         wasEditingOnMouseDownRef,
     } = useTransactionInlineEdit({
-        transactionID,
-        reportID: transactionItem.reportID,
-        reportActionID: transactionItem.reportAction?.reportActionID,
-        parentReportAction,
+        transactionID: transactionItem.transactionID,
         hash: currentSearchHash,
-        fallbackReport: snapshotReport,
+        linkedReportAction: transactionItem.reportAction,
     });
 
     const handleOnPress = () => {
diff --git a/src/hooks/useTransactionInlineEdit.ts b/src/hooks/useTransactionInlineEdit.ts
index 508d01f3972..734d186cfc5 100644
--- a/src/hooks/useTransactionInlineEdit.ts
+++ b/src/hooks/useTransactionInlineEdit.ts
@@ -4,7 +4,7 @@
  * than being duplicated across every surface that renders a transaction.
  */
 import {useCallback, useRef} from 'react';
-// eslint-disable-next-line no-restricted-imports -- Need original useOnyx to avoid reading partial Search snapshot policy data.
+// eslint-disable-next-line no-restricted-imports -- Need original useOnyx to avoid reading partial Search snapshot policy data
 import {useOnyx as originalUseOnyx} from 'react-native-onyx';
 import type {OnyxEntry} from 'react-native-onyx';
 import {useSearchStateContext} from '@components/Search/SearchContext';
@@ -23,28 +23,14 @@ import {getIOUActionForTransactionID} from '@libs/ReportActionsUtils';
 import {isExpenseUnreported, isPerDiemRequest} from '@libs/TransactionUtils';
 import CONST from '@src/CONST';
 import ONYXKEYS from '@src/ONYXKEYS';
-import type {Report, ReportAction, ReportActions} from '@src/types/onyx';
+import type {ReportAction, ReportActions} from '@src/types/onyx';
 import useOnyx from './useOnyx';
 import usePolicyForMovingExpenses from './usePolicyForMovingExpenses';
 import usePolicyForTransaction from './usePolicyForTransaction';
+import useSelfDMReport from './useSelfDMReport';
 
 type UseTransactionInlineEditParams = {
     transactionID: string;
-    reportID: string | undefined;
-
-    /**
-     * When provided the action is looked up directly by ID (faster).
-     * If omitted, the hook scans all actions for the one matching this transaction.
-     * Ignored when `parentReportAction` is supplied directly.
-     */
-    reportActionID?: string;
-
-    /**
-     * Pre-fetched parent report action.
-     * When provided the hook skips its own Onyx subscription entirely, avoiding
-     * a duplicate subscription in components that already hold this data.
-     */
-    parentReportAction?: OnyxEntry<ReportAction>;
 
     /**
      * Search snapshot hash.
@@ -54,11 +40,11 @@ type UseTransactionInlineEditParams = {
     hash?: number;
 
     /**
-     * Fallback report from the search snapshot.
-     * Used when the Onyx report cache is empty (e.g. after cache clear) so that
-     * permission checks like isSettled still have a report object with statusNum.
+     * Lightweight report action hint from the current surface.
+     * Search rows already have this in snapshot data, which lets the hook avoid
+     * scanning all report actions just to recover the thread/report action IDs.
      */
-    fallbackReport?: OnyxEntry<Report>;
+    linkedReportAction?: OnyxEntry<ReportAction>;
 };
 
 type UseTransactionInlineEditReturn = {
@@ -82,39 +68,37 @@ type UseTransactionInlineEditReturn = {
     wasEditingOnMouseDownRef: React.RefObject<boolean>;
 };
 
-function useTransactionInlineEdit({
-    transactionID,
-    reportID,
-    reportActionID,
-    parentReportAction: externalParentReportAction,
-    hash,
-    fallbackReport,
-}: UseTransactionInlineEditParams): UseTransactionInlineEditReturn {
-    // Look up the parent IOU report action from live Onyx. If the caller already
-    // knows the action ID we can select it directly; otherwise we scan all actions.
-    // When the caller supplies `parentReportAction` directly we still must call
-    // useOnyx (rules of hooks) but we ignore its result and prefer the external value.
+function useTransactionInlineEdit({transactionID, hash, linkedReportAction}: UseTransactionInlineEditParams): UseTransactionInlineEditReturn {
+    const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`);
+
+    const reportID = transaction?.reportID;
+    const isUnreported = isExpenseUnreported(transaction);
+    const selfDMReport = useSelfDMReport();
+
+    const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(reportID)}`);
+    const effectiveParentReport = isUnreported ? selfDMReport : parentReport;
+    const effectiveParentReportID = effectiveParentReport?.reportID;
+
+    const linkedReportActionID = linkedReportAction?.reportActionID;
+
     const parentReportActionSelector = useCallback(
-        (reportActions: ReportActions | undefined) => (reportActionID ? reportActions?.[reportActionID] : getIOUActionForTransactionID(Object.values(reportActions ?? {}), transactionID)),
-        [reportActionID, transactionID],
+        (reportActions: ReportActions | undefined) =>
+            linkedReportActionID ? reportActions?.[linkedReportActionID] : getIOUActionForTransactionID(Object.values(reportActions ?? {}), transactionID),
+        [linkedReportActionID, transactionID],
     );
-
-    const [internalParentReportAction] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${getNonEmptyStringOnyxID(reportID)}`, {
+    const [resolvedParentReportAction] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${getNonEmptyStringOnyxID(effectiveParentReportID)}`, {
         selector: parentReportActionSelector,
     });
+    const parentReportAction = resolvedParentReportAction ?? linkedReportAction;
 
-    const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`);
-    const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(reportID)}`);
-
-    const parentReportAction = externalParentReportAction !== undefined ? externalParentReportAction : internalParentReportAction;
+    const transactionThreadReportID = linkedReportAction?.childReportID ?? parentReportAction?.childReportID ?? transaction?.transactionThreadReportID;
 
-    const transactionThreadReportID = parentReportAction?.childReportID;
-    const chatReportID = parentReport?.chatReportID;
+    const chatReportID = effectiveParentReport?.chatReportID;
 
     // For unreported expenses (SelfDM), use active policy to show policy-specific fields like categories and tags.
     const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
-    const reportPolicyID = parentReport?.policyID;
-    const policyID = isExpenseUnreported(transaction) ? activePolicyID : reportPolicyID;
+    const reportPolicyID = effectiveParentReport?.policyID;
+    const policyID = isUnreported ? activePolicyID : reportPolicyID;
 
     const {policy} = usePolicyForTransaction({
         transaction,
@@ -131,7 +115,7 @@ function useTransactionInlineEdit({
     const [chatReportNVP] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${getNonEmptyStringOnyxID(chatReportID)}`);
     const [policyRecentlyUsedCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${getNonEmptyStringOnyxID(policyID)}`);
     const [policyRecentlyUsedTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS}${getNonEmptyStringOnyxID(policyID)}`);
-    const [parentReportNextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${getNonEmptyStringOnyxID(reportID)}`);
+    const [parentReportNextStep] = useOnyx(`${ONYXKEYS.COLLECTION.NEXT_STEP}${getNonEmptyStringOnyxID(effectiveParentReportID)}`);
     // Use original Onyx here because the useOnyx wrapper can read partial Search snapshot policy data instead of the full policy object.
     const [completePolicy] = originalUseOnyx(`${ONYXKEYS.COLLECTION.POLICY}${getNonEmptyStringOnyxID(policyID)}`);
 
@@ -146,9 +130,9 @@ function useTransactionInlineEdit({
     const permissions = getTransactionEditPermissions({
         transaction,
         parentReportAction,
-        parentReport: parentReport ?? fallbackReport,
+        parentReport: effectiveParentReport,
         policy: completePolicy ?? policy,
-        transactionThreadReport: transactionThreadReport ?? parentReport ?? fallbackReport,
+        transactionThreadReport,
         policyCategories,
         policyTags,
         transactionThreadNVP,
@@ -164,8 +148,9 @@ function useTransactionInlineEdit({
         return {
             hash,
             transactionID,
-            parentReport: parentReport ?? fallbackReport,
-            transactionThreadReport: transactionThreadReport ?? parentReport ?? fallbackReport,
+            parentReport: effectiveParentReport,
+            parentReportAction,
+            transactionThreadReport,
             policy: completePolicy ?? policy,
             policyCategories,
             policyTags,
diff --git a/src/libs/actions/TransactionInlineEdit.ts b/src/libs/actions/TransactionInlineEdit.ts
index 9537b8dd4a5..5cceae03eb2 100644
--- a/src/libs/actions/TransactionInlineEdit.ts
+++ b/src/libs/actions/TransactionInlineEdit.ts
@@ -14,11 +14,12 @@ import {getIsOffline} from '@libs/NetworkState';
 import {hasEnabledOptions} from '@libs/OptionsListUtils';
 import Permissions from '@libs/Permissions';
 import {getTagLists, isMultiLevelTags} from '@libs/PolicyUtils';
-import {isMoneyRequestAction} from '@libs/ReportActionsUtils';
+import {getIOUActionForTransactionID, isMoneyRequestAction} from '@libs/ReportActionsUtils';
 import {
     canEditFieldOfMoneyRequest,
     canEditMoneyRequest,
     canUserPerformWriteAction,
+    findSelfDMReportID,
     isArchivedReport,
     isInvoiceReport,
     isIOUReport,
@@ -31,6 +32,7 @@ import CONST from '@src/CONST';
 import ONYXKEYS from '@src/ONYXKEYS';
 import type {
     Beta,
+    IntroSelected,
     Policy,
     PolicyCategories,
     PolicyTagLists,
@@ -38,6 +40,7 @@ import type {
     RecentlyUsedTags,
     Report,
     ReportAction,
+    ReportActions,
     ReportNameValuePairs,
     ReportNextStepDeprecated,
     Transaction,
@@ -51,6 +54,7 @@ import {
     updateMoneyRequestMerchant,
     updateMoneyRequestTag,
 } from './IOU/UpdateMoneyRequest';
+import {createTransactionThreadReport} from './Report';
 
 type TransactionEditPermissions = {
     canEditDate: boolean;
@@ -79,6 +83,24 @@ Onyx.connectWithoutView({
     },
 });
 
+let allReports: NonNullable<OnyxCollection<Report>> = {};
+Onyx.connectWithoutView({
+    key: ONYXKEYS.COLLECTION.REPORT,
+    waitForCollectionCallback: true,
+    callback: (value) => {
+        allReports = value ?? {};
+    },
+});
+
+let allReportActions: NonNullable<OnyxCollection<ReportActions>> = {};
+Onyx.connectWithoutView({
+    key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
+    waitForCollectionCallback: true,
+    callback: (value) => {
+        allReportActions = value ?? {};
+    },
+});
+
 let currentUserAccountID: number = CONST.DEFAULT_NUMBER_ID;
 let currentUserEmail = '';
 Onyx.connectWithoutView({
@@ -97,6 +119,14 @@ Onyx.connectWithoutView({
     },
 });
 
+let introSelected: OnyxEntry<IntroSelected>;
+Onyx.connectWithoutView({
+    key: ONYXKEYS.NVP_INTRO_SELECTED,
+    callback: (value) => {
+        introSelected = value;
+    },
+});
+
 const NO_EDIT: Readonly<TransactionEditPermissions> = Object.freeze({
     canEditDate: false,
     canEditMerchant: false,
@@ -137,6 +167,7 @@ type TransactionEditPermissionsParams = {
 type GetIouParamsInput = {
     transactionID: string;
     parentReport: OnyxEntry<Report>;
+    parentReportAction: OnyxEntry<ReportAction>;
     transactionThreadReport: OnyxEntry<Report>;
     policy: OnyxEntry<Policy>;
     policyCategories: OnyxEntry<PolicyCategories>;
@@ -160,6 +191,7 @@ type TransactionInlineEditParams = GetIouParamsInput & {
 function getIouParamsForTransaction({
     transactionID,
     parentReport,
+    parentReportAction,
     transactionThreadReport,
     policy,
     policyCategories,
@@ -169,12 +201,56 @@ function getIouParamsForTransaction({
     parentReportNextStep,
 }: GetIouParamsInput) {
     const transaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`];
+    const transactionViolations = allTransactionViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`];
+    const isUnreportedExpense = !transaction?.reportID || transaction.reportID === CONST.REPORT.UNREPORTED_REPORT_ID;
+
+    let resolvedParentReport = parentReport;
+    if (!resolvedParentReport?.reportID && transaction?.reportID && transaction.reportID !== CONST.REPORT.UNREPORTED_REPORT_ID) {
+        resolvedParentReport = allReports[`${ONYXKEYS.COLLECTION.REPORT}${transaction.reportID}`];
+    }
+
+    let resolvedParentReportAction = parentReportAction;
+    if (!resolvedParentReportAction && resolvedParentReport?.reportID) {
+        const reportActions = allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${resolvedParentReport.reportID}`] ?? {};
+        resolvedParentReportAction = getIOUActionForTransactionID(Object.values(reportActions), transactionID);
+    }
+
+    if (isUnreportedExpense) {
+        const selfDMReportID = findSelfDMReportID(allReports);
+        if (selfDMReportID) {
+            resolvedParentReport = allReports[`${ONYXKEYS.COLLECTION.REPORT}${selfDMReportID}`] ?? resolvedParentReport;
+
+            if (!resolvedParentReportAction) {
+                const selfDMReportActions = allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${selfDMReportID}`] ?? {};
+                resolvedParentReportAction = getIOUActionForTransactionID(Object.values(selfDMReportActions), transactionID);
+            }
+        }
+    }
+
+    let resolvedTransactionThreadReport = transactionThreadReport;
+    const transactionThreadReportID = resolvedTransactionThreadReport?.reportID ?? transaction?.transactionThreadReportID ?? resolvedParentReportAction?.childReportID;
+
+    if (!resolvedTransactionThreadReport && transactionThreadReportID) {
+        resolvedTransactionThreadReport = allReports[`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`];
+    }
+
+    if (!resolvedTransactionThreadReport && resolvedParentReportAction && transaction) {
+        resolvedTransactionThreadReport = createTransactionThreadReport(
+            introSelected,
+            currentUserEmail,
+            currentUserAccountID,
+            allBetas,
+            resolvedParentReport,
+            resolvedParentReportAction,
+            transaction,
+            transactionViolations,
+        );
+    }
 
     return {
-        // Shared base fields — spread directly into any updateMoneyRequest* call
         transactionID,
-        transactionThreadReport,
-        parentReport,
+        transactionThreadReport: resolvedTransactionThreadReport,
+        parentReport: resolvedParentReport,
         policy,
         policyCategories,
         parentReportNextStep,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mohammadjafarinejad, it looks great. Let’s implement it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ll apply it locally and start full testing while waiting for your push. Please confirm that it fixes the issue without break the current progress.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I'll start testing as well. I'll let you know once I finish testing.

@ahmedGaber93
Copy link
Copy Markdown
Contributor

ahmedGaber93 commented May 6, 2026

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Screen.Recording.2026-05-07.at.4.03.45.AM.mov
Android: mWeb Chrome
Screen.Recording.2026-05-07.at.4.05.48.AM.mov
iOS: HybridApp
Screen.Recording.2026-05-07.at.3.57.14.AM.mov
iOS: mWeb Safari
Screen.Recording.2026-05-07.at.4.03.08.AM.mov
MacOS: Chrome / Safari
Screen.Recording.2026-05-07.at.1.44.13.AM.mov

@ahmedGaber93
Copy link
Copy Markdown
Contributor

This Issue already exists on staging, and not related to our PR

Screen.Recording.2026-05-07.at.1.44.13.AM.mov

@trjExpensify
Copy link
Copy Markdown
Contributor

@ahmedGaber93 are you done with your review?
@mohammadjafarinejad can you fix the conflicts and address any outstanding comments today?

Thanks!

@ahmedGaber93
Copy link
Copy Markdown
Contributor

ahmedGaber93 commented May 8, 2026

Yes, @mohammadjafarinejad just the above 2 comment #89166 (review)

@mohammadjafarinejad
Copy link
Copy Markdown
Contributor Author

@ahmedGaber93 Ready for re-review.

@ahmedGaber93
Copy link
Copy Markdown
Contributor

ahmedGaber93 commented May 11, 2026

@mohammadjafarinejad There’s a new bug where updating the category causes the new value to flicker twice.

Steps to reproduce:

  1. Use a slow network connection.
  2. Edit two cells quickly — for example, edit the category, then quickly edit the merchant.

This looks like a race condition when edit quickly on a slow network connection. Maybe not related to latest changes.

Screen.Recording.2026-05-11.at.12.24.17.PM.mov
Screen.Recording.2026-05-11.at.1.00.52.PM.mov

@ahmedGaber93
Copy link
Copy Markdown
Contributor

@mohammadjafarinejad I finished my review, tested well and works as expected, except for the issue mentioned above.

@mohammadjafarinejad
Copy link
Copy Markdown
Contributor Author

@ahmedGaber93 This is my guess, WDYT?

We are applying two updates on a slow network, and both updates are happening sequentially at same time:

  1. Update the category from A → B
  2. Update the merchant from A → B

The server receives the first update and returns a response that updates the search snapshot (the server response still contains the old merchant value (A)). So the merchant gets reverted from BA.

Then the server receives the second update, and the merchant changes back from AB.

@ahmedGaber93
Copy link
Copy Markdown
Contributor

@mohammadjafarinejad This maybe what happened on the second video, but not sure if this the case on the first video

Are you able to reproduce the case on the first video?

@mohammadjafarinejad
Copy link
Copy Markdown
Contributor Author

@ahmedGaber93 Yes, i can reprduce both of them (in slow network only), I think the first video is likely the same issue, but on the same field:

  • merchant changes from A -> B
  • then quickly from B -> C

On a slow network, the first response can arrive after the UI already shows C, but that older response still contains B, so the UI briefly reverts from C -> B. Then the second response arrives and changes it back from B -> C.

@ahmedGaber93
Copy link
Copy Markdown
Contributor

Ah, I think this may also be caused by the side-effect API/search call triggered after any transaction change.

After the first edit, once UpdateMoneyRequestCategory finishes, the app triggers an API/search side-effect call. If the user edits the category again before API/search completes, the optimistic value gets overridden by the stale response from that API/search call.

Then, after the second UpdateMoneyRequestCategory API finishes, the value updates correctly again.

Screen.Recording.2026-05-12.at.9.40.58.AM.mov

@ahmedGaber93
Copy link
Copy Markdown
Contributor

ahmedGaber93 commented May 12, 2026

follow-ups if they not blockers

  1. Reports - Category picker is opened overlapping the "Category" cell during inline editing. #88681
    → UX edge case, not blocking

  2. Spend-The newly added expense highlights every time updating other expense #88659
    → Same behavior on production, newly added expense highlights every time any other report is opened

  3. Inline edit for description on multiline if it still required

  4. Discussing/Handling accessibility if it's required as mentioned here

  5. API race condition when edit quickly on a slow network connection video here

@ahmedGaber93
Copy link
Copy Markdown
Contributor

@mohammadjafarinejad I think we should mention in the QA steps that QA needs to follow the steps from the blocker issues (or please add them here), except for the issues that will be fixed in follow-up PRs: #88681 and #88659, for better clarification.

Copy link
Copy Markdown
Contributor

@ahmedGaber93 ahmedGaber93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Follow-ups if they not blockers #89166 (comment)

@melvin-bot melvin-bot Bot requested a review from puneetlath May 12, 2026 07:09
Copy link
Copy Markdown
Contributor

@puneetlath puneetlath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, behemoth of a PR. Was a tough review. I left a couple of minor comments.

shouldDisplayBelowModals?: boolean;

/**
* Whether a RIGHT_DOCKED modal should keep its backdrop when rendered in a narrow pane context.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we give a little more detail in this comment itself on what the considerations are for why this would be true or false.

* @returns The string with all line breaks removed
*/
function removeLineBreaks(text = '') {
return text.replaceAll(CONST.REGEX.LINE_BREAK, '');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the line breaks not be spaces? Like would this turn this:

this is line one
this is line two

Into this:

this is line onethis is line two

@puneetlath
Copy link
Copy Markdown
Contributor

Follow-ups if they not blockers #89166 (comment)

@ahmedGaber93 are you asking whether these should be blockers?

@ahmedGaber93
Copy link
Copy Markdown
Contributor

@ahmedGaber93 are you asking whether these should be blockers?

@puneetlath yes, WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants